package cn.mldn.microboot.util.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * description:
 * Created by gy on 2017/8/12.
 */
public class AbstractBaseController {

    @Autowired
    private MessageSource messageSource;

    public String getMessage(String key,String... args){
        return this.messageSource.getMessage(key,args, Locale.getDefault());
    }

    @InitBinder
    public void initBinder(WebDataBinder binder){
        binder.registerCustomEditor(Date.class,new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),true));
    }
}
